//1-1
//数组
val array = Array(1,2,3,4,5)
val rdd = sc.parallelize(array)
//列表
val list = List(1,2,3,4,5)
val rdd = sc.parallelize(list)

//1-2
//hdfs
val lines = sc.textFile("hdfs://192.168.137.120:9000/word.txt")
//本地
val lines = sc.textFile("B:word.txt")

//2-1
//map
val x = sc.parallelize(Array("b","a","c"))
val y = x.map(z => (z,1))
println(x.collect().mkString(", "))
println(y.collect().mkString(", "))
//filter
val x = sc.parallelize(Array(1,2,3))
val y = x.filter(n => n == 1)
println(x.collect().mkString(", "))
println(y.collect().mkString(", "))
//flatMap
val x = sc.parallelize(Array(1,2,3))
val y = x.flatMap(n => Array(n, n * n, -1))
println(x.collect().mkString(", "))
println(y.collect().mkString(", "))

//2-2
//groupby
val x = sc.parallelize(Array("John","Fred","Anna","James"))
val y = x.groupBy(w => w.charAt(0))
println(x.collect().mkString(", "))
println(y.collect().mkString(", "))
//distinct
val x = sc.parallelize(Array(1,2,3,3,4))
val y = x.distinct()
println(x.collect().mkString(", "))
println(y.collect().mkString(", "))
//coalesce
val x = sc.parallelize(Array(1,2,3,4,5),3)
val y = x.coalesce(2)
val xOut = x.glom().collect
val yOut = y.glom().collect